import type { AuthModel } from './model/auth';

import { baseRequestClient, requestClient } from '#/api/request';
import { ServicePrefixEnum } from '#/enums/commonEnum';

/**
 * 登录
 */
export async function loginApi(data: AuthModel.LoginParams) {
  return requestClient.post<AuthModel.LoginResultVO>(
    `${ServicePrefixEnum.OAUTH}/anyTenant/login`,
    data,
  );
}

/**
 * 刷新accessToken
 */
export async function refreshTokenApi(params: AuthModel.RefreshParams) {
  return requestClient.post<AuthModel.LoginResultVO>(
    `${ServicePrefixEnum.OAUTH}/anyTenant/refresh`,
    undefined,
    { params },
  );
}

/**
 * 退出登录
 */
export async function logoutApi() {
  return baseRequestClient.post(`${ServicePrefixEnum.OAUTH}/anyUser/logout`);
}
/**
 * 发送短信验证码
 */
export async function sendSmsCode(mobile: string, templateCode: string) {
  return baseRequestClient.get(
    `${ServicePrefixEnum.OAUTH}/anyTenant/sendSmsCode`,
    {
      params: {
        mobile,
        templateCode,
      },
      requestOptions: {
        withoutTenant: false,
      },
    },
  );
}

/**
 * 发送邮件验证码
 */
export async function sendEmailCode(email: string, templateCode: string) {
  return baseRequestClient.get(
    `${ServicePrefixEnum.OAUTH}/anyTenant/sendEmailCode`,
    {
      params: {
        email,
        templateCode,
      },
      requestOptions: {
        withoutTenant: false,
      },
    },
  );
}

/**
 * 根据手机号注册
 */
export async function registerByMobile(params: AuthModel.RegisterByMobileVO) {
  return baseRequestClient.post(
    `${ServicePrefixEnum.OAUTH}/anyTenant/registerByMobile`,
    params,
    {
      requestOptions: {
        withoutTenant: false,
      },
    },
  );
}
